package com.heima.admin.controller.v1;

import com.heima.admin.service.SensitiveService;
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.dtos.SensitivePageDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;

@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController {
    @Autowired
    IWemediaClient iWemediaClient;



    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return iWemediaClient.delete(id);
    }

    @PostMapping("save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive) throws InvocationTargetException, IllegalAccessException {
        return iWemediaClient.create(wmSensitive);
    }

    @PostMapping("list")
    public ResponseResult findbylist(@RequestBody SensitivePageDto sensitivePageDto) {
//       ResponseResult sensitiveList = iWemediaClient.findbylist(sensitivePageDto);
//       if(sensitiveList.getCode()!=200){
//           return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"findSensitiveList 远程调用失败");
//       }
//
//       ResponseResult.okResult(sensitiveList.getData());
//       return sensitiveService.findlist(sensitivePageDto);
//   }
        ResponseResult responseResult = iWemediaClient.findbylist(sensitivePageDto);
        if (responseResult.getCode() != 200) {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "findSensitiveList 远程调用失败");
        }
        return ResponseResult.okResult(responseResult.getData());

    }
    @PostMapping("update")
    public ResponseResult update(@RequestBody SensitiveDto sensitiveDto) throws InvocationTargetException, IllegalAccessException {
        return iWemediaClient.update(sensitiveDto);
    }

}